<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="门户标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="siteTitle">
              <a-input v-model="model.siteTitle" placeholder="请输入门户标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="门户Logo" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="siteLogo">
              <j-image-upload isMultiple v-model="model.siteLogo"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="管理系统标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="adminTitle">
              <a-input v-model="model.adminTitle" placeholder="请输入管理系统标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="管理系统Logo" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="adminLogo">
              <j-image-upload isMultiple v-model="model.adminLogo"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="登录背景" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signInBackground">
              <j-image-upload isMultiple v-model="model.signInBackground"></j-image-upload>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item
              label="首页新闻主图(600x400)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="homeNewsCover"
            >
              <j-image-upload :isMultiple="false" v-model="model.homeNewsCover"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="首页会议主图(600x400)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="homeIndustryCover"
            >
              <j-image-upload :isMultiple="false" v-model="model.homeIndustryCover"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="首页专题主图(600x400)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="homeForumsCover"
            >
              <j-image-upload :isMultiple="false" v-model="model.homeForumsCover"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="隐私政策" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="privacy">
              <j-editor v-model="model.privacy" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'HTBasicSettingsForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/settings/hTBasicSettings/add',
        edit: '/settings/hTBasicSettings/edit',
        queryById: '/settings/hTBasicSettings/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    }
  }
}
</script>

